package com.qf.test5;

import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 连接Redis集群
 * @author zjw
 * @description
 * @date 2021/11/2 11:45
 */
public class DemoTest {

    @Test
    public void test(){
        // 准备6个节点
        Set<HostAndPort> nodes = new HashSet<>();
        nodes.add(new HostAndPort("192.168.41.41",7001));
        nodes.add(new HostAndPort("192.168.41.41",7002));
        nodes.add(new HostAndPort("192.168.41.41",7003));
        nodes.add(new HostAndPort("192.168.41.41",7004));
        nodes.add(new HostAndPort("192.168.41.41",7005));
        nodes.add(new HostAndPort("192.168.41.41",7006));

        // 构建操作对象,全局一个即可，内部自动释放资源
        JedisCluster jedisCluster = new JedisCluster(nodes);

        // 操作
        String a = jedisCluster.get("a");
        System.out.println(a);

        // JedisCluster没有提供keys方法， 后期学习SpringBoot，提供了data-redis，里面封装好了keys操作
    }


}
